/********************************************************************************
 * @Author: Zhenzhou Liu
 * @Date: 2025-01-09
 * @Description: 
 *******************************************************************************/
#include<stdio.h>
#include <stdlib.h>

typedef struct StackNode {
    int val;
    int min;
    struct StackNode *next;
} StackNode;

typedef struct {
    StackNode *topNode;
} MinStack;


MinStack* minStackCreate() {
    MinStack *temp = (MinStack *)malloc(sizeof(MinStack));
    temp->topNode = NULL;
    return temp;
}

void minStackPush(MinStack* obj, int val) {
    StackNode *newNode = (StackNode *)malloc(sizeof(StackNode));
    if (obj->topNode == NULL)
        newNode->min = val;
    else
        newNode->min = (val < obj->topNode->min) ? val : obj->topNode->min;
    newNode->val = val;
    newNode->next = obj->topNode;
    obj->topNode = newNode;
}

void minStackPop(MinStack* obj) {
    StackNode * temp = obj->topNode;
    obj->topNode = temp->next;
    free(temp);
}

int minStackTop(MinStack* obj) {
    return obj->topNode->val;
}

int minStackGetMin(MinStack* obj) {
    return obj->topNode->min;
}

void minStackFree(MinStack* obj) {
    while (obj->topNode != NULL) {
        StackNode *temp = obj->topNode;
        obj->topNode = temp->next;
        free(temp);
    }
}